<style>
.layui-inline label {
	width: 130px;
}

.layui-form-label {
	width: 130px;
}

.layui-input-block {
	margin-left: 170px;
}
</style>
<div class="layui-fluid layui-anim febs-anim" id="febs-table-container" lay-title="Error Code">
	<div class="layui-row febs-container">
		<div class="layui-col-md12">
			<div class="layui-card">
				<div class="layui-card-body febs-table-full">
					<form class="layui-form layui-table-form" lay-filter="search-table-form">
						<div class="layui-row">
							<div class="layui-col-md10">
								<div class="layui-form-item">
									<div class="layui-inline">
										<label class="layui-form-label layui-form-label-sm">ERROR CODE</label>
										<div class="layui-input-inline">
											<input type="text" name="errorcode" autocomplete="off" class="layui-input">
										</div>
									</div>
									<div class="layui-inline">
										<label class="layui-form-label layui-form-label-sm">IS HANDELED FLAG </label>
										<div class="layui-input-inline">
											<select name="isHandledFlag" lay-verify="required">
												<option value="">All</option>
												<option value=1>True</option>
												<option value=0>False</option>
											</select>
										</div>
									</div>
								</div>
							</div>
							<div class="layui-row">
								<div class="layui-col-md10">
									<div class="layui-form-item">
										<div class="layui-inline">
											<label class="layui-form-label layui-form-label-sm">CREATE TIME</label>
											<div class="layui-input-inline">
												<input type="text" name="createTime" id="createTime" class="layui-input">
											</div>
										</div>
									</div>
								</div>
								<div class="layui-col-md2 layui-col-sm12 layui-col-xs12 table-action-area">
									<div class="layui-btn layui-btn-sm layui-btn-primary table-action" id="query">
										<i class="layui-icon">&#xe848;</i>
									</div>
									<div class="layui-btn layui-btn-sm layui-btn-primary table-action" id="refresh">
										<i class="layui-icon">&#xe79b;</i>
									</div>
									<div class="layui-btn layui-btn-sm layui-btn-primary table-action action-more"
										shiro:hasAnyPermissions="fdiErrorrecord:add,fdiErrorrecord:update,fdiErrorrecord:export">
										<i class="layui-icon">&#xe875;</i>
									</div>
								</div>
							</div>
					</form>
					<table lay-filter="mainTable" lay-data="{id: 'mainTable'}"></table>
				</div>
			</div>
		</div>
	</div>
</div>
<script type="text/html" id="table-options">
    <span shiro:lacksPermission="fdiErrorrecord:view,fdiErrorrecordr:update,fdiErrorrecord:delete">
        <span class="layui-badge-dot febs-bg-orange"></span> No Permission
    </span>
    <a lay-event="edit" shiro:hasPermission="fdiErrorrecord:update"><i
            class="layui-icon febs-edit-area febs-blue">&#59455;</i></a>
    <a lay-event="del" shiro:hasPermission="fdiErrorrecord:delete"><i class="layui-icon febs-edit-area febs-red">&#59385;</i></a>
</script>
<script data-th-inline="none" type="text/javascript">
	var tableData;
	layui
			.use([ 'dropdown' ,'jquery' ,'laydate' ,'form' ,'table' ,'febs' ,'laydate' ],
					function(){
						var $ = layui.jquery , laydate = layui.laydate , febs = layui.febs , form = layui.form , table =
								layui.table , treeSelect = layui.treeSelect , dropdown = layui.dropdown , $view =
								$('#febs-table-container') , $query = $view.find('#query') , $refresh =
								$view.find('#refresh') , $searchForm = $view.find('form') , sortObject = {
							field : 'createTime' ,
							type : null
						} , tableIns;
						form.render();
						laydate.render({
							elem : '#createTime',
							type: 'datetime',
							range : true ,
							trigger : 'click'
						});
						initTable();
						dropdown.render({
							elem : $view.find('.action-more') ,
							click : function(name, elem, event){
								var checkStatus = table.checkStatus('mainTable');
								if (name === 'add') {
									febs.modal.open('NEW', 'fdi/fdiErrorrecord/add', {
										btn : [ 'Commit' ,'Reset' ] ,
										area : $(window).width() <= 750 ? '95%' : '50%' ,
										yes : function(index, layero){
											$('#modal-add').find('#submit').trigger('click');
										} ,
										btn2 : function(){
											$('#modal-add').find('#reset').trigger('click');
											return false;
										}
									});
								}
								if (name === 'delete') {
									if (!checkStatus.data.length) {
										febs.alert.warn('Please select one row to delete!');
									} else {
										febs.modal.confirm('DELETE', 'Are you sure you want to delete this？？',
												function(){
													var ids = [ ];
													layui.each(checkStatus.data, function(key, item){
														ids.push(item.id);
													});
													deleteItems(ids);
												});
									}
								}
								if (name === 'export') {
									var params = $.extend(getQueryParams(), {
										field : sortObject.field ,
										order : sortObject.type
									});
									params.pageSize = $view.find(".layui-laypage-limits option:selected").val();
									params.pageNum = $view.find(".layui-laypage-em").next().html();
									//                     febs.download(ctx + 'user/excel', params, 'mappinglist.xlsx');
								}
							} ,
							options : [ {
								name : 'add' ,
								title : 'New' ,
								perms : 'fdiErrorrecord:add'
							} ,{
								name : 'delete' ,
								title : 'Delete Selected' ,
								perms : 'fdiErrorrecord:delete'
							} ,{
								name : 'export' ,
								title : 'Export Excel' ,
								perms : 'fdiErrorrecord:export'
							} ]
						});
						table.on('tool(mainTable)', function(obj){
							var data = obj.data , layEvent = obj.event;

							if (layEvent === 'del') {
								febs.modal.confirm('DELETE', 'Are you sure you want to delete this？', function(){
									deleteItems(data.id);
								});
							}
							if (layEvent === 'edit') {
								tableData = data;
								febs.modal.open('MODIFY', 'fdi/errorrecordConfig/update', {
									area : $(window).width() <= 750 ? '90%' : '50%' ,
									btn : [ 'Commit' ,'Reset' ] ,
									yes : function(index, layero){
										$('#modal-update').find('#submit').trigger('click');
									} ,
									btn2 : function(){
										layer.closeAll();
									}
								});
							}
						});
						table.on('sort(mainTable)', function(obj){
							sortObject = obj;
							tableIns.reload({
								initSort : obj ,
								where : $.extend(getQueryParams(), {
									field : obj.field ,
									order : obj.type
								})
							});
						});
						$query.on('click', function(){
							var params = $.extend(getQueryParams(), {
								field : sortObject.field ,
								order : sortObject.type
							});
							tableIns.reload({
								where : params ,
								page : {
									curr : 1
								}
							});
						});
						$refresh.on('click', function(){
							$searchForm[0].reset();
							sortObject.type = 'null';
							tableIns.reload({
								where : getQueryParams() ,
								page : {
									curr : 1
								} ,
								initSort : sortObject
							});
						});
						function initTable(){
							tableIns = febs.table.init({
								elem : $view.find('table') ,
								id : 'mainTable' ,
								url : ctx + 'fdiErrorrecord/list' ,
								cols : [ [ {
									type : 'checkbox'
								} ,{
									field : 'id' ,
									hide : true ,
									title : 'ID' ,
									width : 20
								} ,{
									field : 'errorcode' ,
									title : 'ERROR CODE'
								} ,{
									field : 'context' ,
									title : 'CONTEXT'
								} ,{
									field : 'category' ,
									title : 'CATEGORY',
									hide  : true
								} ,{
									field : 'description' ,
									title : 'DESCRIPTION'
								} ,{
									field : 'isHandledFlag' ,
									title : 'IS HANDLED',templet: function(d){return  d.isHandledFlag===1?'TRUE':'FALSE'}
								} ,{
									field : 'createTime' ,
									title : 'CREATE TIME'
								} ,{
									title : 'Actions' ,
									align : 'center' ,
									toolbar : '#table-options'
								} ] ]
							});
						}
						function getQueryParams(){
							var createTimeFrom , createTimeTo , createTime =
									$searchForm.find('input[name="createTime"]').val();
							if (createTime) {
								createTimeFrom = createTime.split(' - ')[0];
								createTimeTo = createTime.split(' - ')[1];
							}
							return {
								createTimeFrom : createTimeFrom ,
								createTimeTo : createTimeTo ,
								errorcode : $searchForm.find('input[name="errorcode"]').val().trim() ,
								isHandledFlag : $searchForm.find("select[name='isHandledFlag']").val() ,
								invalidate_ie_cache : new Date()
							};
						}
						function deleteItems(ids){
							febs.get(ctx + 'fdiErrorrecord/delete/' + ids, null,function(){
								febs.alert.success('Delete Successfully!');
								//                 $query.click();
							});
						}
					})
</script>